/*
 * This file is part of the Boring Engine's Kirby Game.
 *
 * Copyright (c) 2011 by pf5234 <pf5234@users.sourceforge.net>.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package kirby;

import com.googlecode.boringengine.lua.LuaFunction;

public abstract class Enemy extends GameObject {

    protected int health, maxHealth;
    protected boolean isFlipped, beingEaten;
    protected double gravity;

    @LuaFunction
    public int getHealth() {
        return health;
    }

    @LuaFunction
    public int getMaxHealth() {
        return maxHealth;
    }

    public boolean isEdible() {
        return true;
    }

    public boolean isDead() {
        return health < 1;
    }

    @Override
    public void update() {
        if (beingEaten) return;
        super.update();
        //update0();
    }

    public void die() { health = -999; }

    protected void updateGravity() {
        gravity += .25;
        double gravabs = Math.abs(gravity);
        for (int i = 0; i < gravabs; i++) {
            int canMove = CollisionDetection.canMoveToY(x, y, w, h, (int)(gravabs/gravity));
            if (canMove == CollisionDetection.CANT_MOVE) {
                    gravity = 0;
                break;
            }
            y += gravabs/gravity;
        }
    }

    public void beingEaten() {
        beingEaten = true;
    }

    public void beenEaten() {
        health = -999;
    }

    public abstract String getType();
    public abstract void update0();

    @LuaFunction
    public void heal(int healz) {
        health += healz;
        if (health > maxHealth) health = maxHealth;
    }

    @LuaFunction
    public void gainMaxHealth(int gain) {
        health += gain;
        maxHealth += gain;
    }

}
